package com.example.testpic;

import java.io.IOException;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class SendImageItemAdapter extends BaseAdapter {
	private Context context;
	private List<String> bitmapList;

	public SendImageItemAdapter(Context context,List<String> bitmaps){
		this.context = context;
		this.bitmapList = bitmaps;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		int count = 0;
		if (bitmapList != null) {
			count = bitmapList.size();
		}
		return count;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return bitmapList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void setDataList(List<String> bitmaps){
		this.bitmapList = bitmaps;
	}
	
	public List<String> getDataList(){
		return bitmapList;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.send_image_item, null);
		}
		String imagePath = (String) getItem(position);
		Bitmap imageBitmap = null;
		try {
			imageBitmap = Bimp.revitionImageSize(imagePath, 256, 256);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ImageView imageItemView = (ImageView) convertView.findViewById(R.id.image_item);
		imageItemView.setImageBitmap(imageBitmap);
		return convertView;
	}

}
